package cn.wolfcode.producer._05_delay;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class Producer {

    public static void main(String[] args) throws Exception {
        //1 创建消息的发送者
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("producer-demo");
        //2 设置名字服务
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        //3 启动生产者
        defaultMQProducer.start();
        //4 创建消息
        //4.1 创建消息对象(指定主题以及发送的内容[数组的形式])
        Message message = new Message("05-delay", "Hello RocketMQ".getBytes());
        //设置发送延迟时间
        message.setDelayTimeLevel(2);
        //4.2 发送消息
        SendResult sendResult = defaultMQProducer.send(message);
        System.out.println(sendResult.getSendStatus());//查看发送的状态
        System.out.println(sendResult.getMsgId());//查看消息的id
        //5 关闭连接
        defaultMQProducer.shutdown();
    }
}
